<link rel="stylesheet" href="{__SYSTEM_PATH__}/js/layui/css/dropdown.css">
<div class="row content-nav">
    <div class="col-xs-12">
        <ul>
            <li><a href="javascript:;"><i></i>&nbsp;任务管理</a></li>
            <li><a href="javascript:;">任务列表</a></li>
        </ul>
    </div>
</div>

<div class="layui-fluid" id="search-box">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form layui-form-pane" action="">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label seller-inline-2">任务分类：</label>
                        <div class="layui-input-inline seller-inline-4">
                        <select name="type_id">
                            <option value="">全部</option>
                            {if !empty($type_list)}
                            {volist name="type_list" id="value"}
                            <option value="{$value.id}">{$value.level|raw}{$value.name|raw}</option>
                            {/volist}
                            {/if}
                        </select>   
                        </div>
                    </div>
                    
                    <div class="layui-inline">
                        <label class="layui-form-label seller-inline-2">任务状态：</label>
                        <div class="layui-input-inline seller-inline-4">
                            <select name="status">
                                <option value="">全部</option>
                                 {if !empty($status_list)}
                                  {volist name="status_list" id="item" key="k"}
                                    <option value="{$k}">{$item}</option>
                                  {/volist}
                                 {/if}
                            </select> 
                        </div>
                    </div>                   
                </div>
                
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label seller-inline-2">发布用户：</label>
                        <div class="layui-input-inline seller-inline-4">
                            <input type="text" name="publisher" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                        </div>
                    </div> 	                
				    <div class="layui-inline">
				      <label class="layui-form-label">发布时间</label>
				      <div class="layui-input-inline" style="width:300px;">
				        <input type="text" class="layui-input" id="publish_time" name="publish_time" placeholder=" - ">
				      </div>
				    </div>				    
                    
                    <div class="layui-inline">
                        <button type="button" id="search-btn" class="layui-btn layui-btn-sm layui-bg-light-blue"><i class="layui-icon layui-icon-search"></i> 搜索</button>
                    </div>
                </div>
                
            </form>
        </div>
    </div>
</div>

<section class="content clearfix">
    <div class="layui-list-box">
        <table class="layui-hide" id="list-box" lay-filter="list-box"></table>
    </div>
</section>

<script type="text/html" id="list-toolbar">
    <div class="layui-btn-container">
        <button lay-event="url" type="button" class="layui-btn layui-btn-sm layui-bg-light-blue"><i class="layui-icon">&#xe61f;</i> 添加</button>
        <button lay-event="refresh" type="button" class="layui-btn layui-btn-sm layui-bg-red"><i class="layui-icon">&#xe9aa;</i> 刷新</button>
    </div>
</script>

<script type="text/html" id="list-bar">
    <button class="layui-btn layui-btn-xs layui-btn-danger" lay-dropdown="{align:'right', menus: [{layIcon:'layui-icon-username',txt: '团购', event:'regiment'},{layIcon:'layui-icon-fire',txt: '秒杀', event:'second'},{layIcon:'layui-icon-diamond',txt: '积分', event:'point'}, {layIcon: 'layui-icon-edit',txt: '编辑', event:'edit'}, {layIcon: 'layui-icon-delete', txt: '删除', event:'del'}]}">
        <span>操作</span>
        <i class="layui-icon layui-icon-triangle-d"></i>
    </button>
</script>

<script>
layui.config({
    base: "{__SYSTEM_PATH__}/js/layui/extend/"
}).use(['table','dropdown','form','laydate'], function () {
    var table = layui.table;
    var dropdown = layui.dropdown;
    var form = layui.form;
    var laydate = layui.laydate;
	  laydate.render({
	    elem: '#publish_time'
	    ,type: 'datetime'
		,range: '~'
	  });   

    table.render({
        elem: '#list-box'
        , url: '{:createUrl("index")}'
        , toolbar: '#list-toolbar'
        , defaultToolbar: []
        , title: '数据表'
        , cols: [[
                  {type: 'checkbox'}
                , {field: 'job_no', title: '任务单号', width: 180,align:"center"}
                , {field:"type_name",title:"任务分类",align:"center"}
                , {field:"num",title:"任务单数",width:90,align:"center"}
                , {field:"accept_num",title:"接单数",width:90,align:"center"}
                , {field:"price",title:"任务价格",width:90,align:"center"}
                , {field:"total_amount",title:"任务总金额",width:100,align:"center"}
                , {field:"publisher",title:"发布人",width:120,align:"center"}
                , {field:"publish_time",title:"发布时间",width:160,align:"center"}
                , {field:"exp_time",title:"过期时间",width:160,align:"center"}
                // , {fixed: 'right', align: 'center', title: '操作', toolbar: '#list-bar', width: 100}
            ]]
        , done: function (res) {
            dropdown.suite();
        }
        , page: true
        , id: 'list-table'
        , height: 'full-310'
        // ,limit:30
    });

    $("#search-btn").on("click",function (){
        //执行重载
        table.reload('list-table', {
          page: {
            curr: 1
          }
          ,where: {
            key: {
              type_id : $('[name="type_id"]').val(),
              publisher : $('[name="publisher"]').val(),
              status : $('[name="status"]').val(),
              publish_time : $('[name="publish_time"]').val()
            }
          }
        }, 'data');
    });

    //头工具栏事件
    table.on('toolbar(list-box)', function (obj) {
        switch (obj.event) {
            case 'url':
                window.location.href = "{:createUrl('editor')}";
                break;
            case 'refresh':
                window.location.reload();
                break;
        }
    });

    //监听行工具事件
    table.on('tool(list-box)', function (obj) {
        var data = obj.data;
        if (obj.event === 'del') {
            layer.confirm('你确定要删除吗？', function (index) {
                $.get('{:createUrl("delete")}',{
                    id : data.id
                },function(result){
                    layer.close(index);
                    if(result.code){
                        obj.del();
                    }else{
                        layer.msg(result.msg,{ icon : 2 });
                    }
                },"json");
            });
        } else if (obj.event === 'edit') {
            window.location.href = '{:createUrl("editor")}?id='+data.id;
        }else if(obj.event == 'group'){
            window.location.href = '{:createUrl("editor_group")}?id='+data.id;
        }else if(obj.event == 'regiment'){
            window.location.href = '{:createUrl("editor_regiment")}?id='+data.id;
        }else if(obj.event == 'second'){
            window.location.href = '{:createUrl("editor_second")}?id='+data.id;
        }else if(obj.event == 'point'){
            window.location.href = '{:createUrl("editor_point")}?id='+data.id;
        }
    });
    
    //监听单元格编辑
    table.on('edit(list-box)', function(obj){
        $.get('{:createUrl("field")}',{
            name : obj.field,
            value : obj.value,
            id : obj.data.id
        },function (result){
            if(!result.code){
                layer.msg(result.msg,{ icon : 2 });
            }
        },"json");
    });
    
});
</script>





